package com.rongshu.view.login.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.utils.Constant;
import com.rongshu.view.login.activity.LoginQuestionDetailsActivity;
import com.rongshu.view.login.entity.LoginQuestion;

import java.util.List;

public class LoginQuestionAdapter extends RecyclerView.Adapter<LoginQuestionAdapter.QuestionViewHolder> {

    private List<LoginQuestion.ResponseBean> mResponseBeanList;
    private Context mContext;

    public LoginQuestionAdapter(List<LoginQuestion.ResponseBean> responseBeanList, Context context) {
        this.mResponseBeanList = responseBeanList;
        this.mContext = context;
    }

    public void setNewData(List<LoginQuestion.ResponseBean> responseBeanList) {
        this.mResponseBeanList = responseBeanList;
    }

    @NonNull
    @Override
    public QuestionViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_login_question_item, viewGroup, false);
        return new QuestionViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull QuestionViewHolder questionViewHolder, final int i) {
        questionViewHolder.txtQuestion.setText(mResponseBeanList.get(i).getTitle());
        questionViewHolder.txtQuestion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, LoginQuestionDetailsActivity.class);
                intent.putExtra(Constant.INTENT_DATA, mResponseBeanList.get(i));
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mResponseBeanList.size();
    }

    public static class QuestionViewHolder extends RecyclerView.ViewHolder {

        private TextView txtQuestion;

        public QuestionViewHolder(@NonNull View itemView) {
            super(itemView);
            txtQuestion = itemView.findViewById(R.id.txtQuestion);
        }
    }
}
